<!-- 司机编辑 - 综合表单页面 -->
<template>
    <div class="page-container">
        <el-form ref="form" :model="form" :label-width="$globalCss.formLabelWidth_default" :rules="formRules"
            v-loading="loading" label-position="right" class="common-form-row">

            <ex_header_spiler :title="$tt('label_base_info')"></ex_header_spiler>

            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_driver_name')" prop="driverName" class=" ">
                        <ex_super_input v-model="form.driverName" class="w_fill" maxlength="20" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_phone_number')" prop="phone" class=" ">
                        <ex_super_input v-model="form.phone" class="w_fill" maxlength="20" show-word-limit />
                    </el-form-item>
                </el-col>
            </el-row>

            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_driving_years')" prop="drivingExperience" class=" ">
                        <ex_super_input v-model="form.drivingExperience" class="w_fill" type="input-number" :min="0" />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_tms_license_type')" prop="driverLicenseType" class=" ">
                        <ex_super_input v-model="form.driverLicenseType" class="w_fill" type="select"
                            enum="DriverLicenseTypeEnum" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_tms_license_indate')" prop="driverLicenseExpiredDate" class=" ">
                        <ex_super_input v-model="form.driverLicenseExpiredDate" class="w_fill" type="date-picker" />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_home_city')" prop="ownerCity" class=" ">
                        <china_address_select :province.sync="form.ownerProvince" :city.sync="form.ownerCity" :level="1"
                            class="w_fill" />
                    </el-form-item>
                </el-col>
            </el-row>




            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_card_no')" prop="idNo" class=" ">
                        <ex_super_input v-model="form.idNo" class="w_fill" maxlength="20" show-word-limit />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_card_date')" prop="idExpiredDate" class=" ">
                        <ex_super_input v-model="form.idExpiredDate" class="w_fill" type="date-picker" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_affiliated_supplier')" prop="supplierId" class=" ">
                        <ex_super_input :value="form.supplierId" class="w_fill" type="select"
                            url="/srm-api/supplier/SupplierRpc/getSupplierDict.json" storeData
                            :listHandler=" e => e.map(it => {
                              it.disabled = it.status === 'DISABLED'
                              return it
                            })"
                            :option="{ label: 'supplierName', value: 'supplierId' }" @changeItem="e => {
                                if (!e) e = { supplierName: null, supplierId: null, supplierCode: null }
                                form.supplierName = e.supplierName
                                form.supplierId = e.supplierId
                            }" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-row>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_card_head_portrait_img')" prop="idHeadUrl" class=" ">
                        <ex_super_input v-model="form.idHeadUrl" class="w_fill" type="upload-img" />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_card_national_img')" prop="idBackUrl" class=" ">
                        <ex_super_input v-model="form.idBackUrl" class="w_fill" type="upload-img" />
                    </el-form-item>
                </el-col>
                <el-col>
                    <el-form-item :label="$tt('label_tms_driver_license_photo')" prop="driverLicenseUrl" class=" ">
                        <ex_super_input v-model="form.driverLicenseUrl" class="w_fill" type="upload-img" />
                    </el-form-item>
                </el-col>
            </el-row>
            <el-form-item label-width="0">
                <span>
                    <el-button type="primary" @click="submit">{{ $tt('label_save') }}</el-button>
                    <el-button @click="pageBack">{{ $tt('label_fms_account_config_cancel') }}</el-button>
                </span>
            </el-form-item>
        </el-form>
    </div>
</template>
<script>

import router_params from '@/mixin/router_params';
import china_address_select from '@/component/tms/china_address_select'
let defaultObj = {
    // id: null,//long
    driverName: null,//	string 	司机名称
    phone: null,//	string 	手机号码
    driverLicenseType: null,//	DriverLicenseTypeEnum 	A1:A1, A2:A2, A3:A3, B1:B1, B2:B2, C1:C1, C2:C2
    driverLicenseExpiredDate: null,//	long 	驾驶证有效期
    supplierId: null,//	long 	所属供应商id
    supplierName: null,//	string 	所属供应商名称
    ownerCity: null,//	string 	所属城市
    idNo: null,//	string 	身份证
    idExpiredDate: null,//	long 	身份证有效期
    idHeadUrl: null,//	string 	身份证图片
    idBackUrl: null,//	string 	身份证图片
    driverLicenseUrl: null,//	string 	驾驶证图片
    drivingExperience: null,//	integer 	驾龄
}
export default {
    name: 'driver_operate',
    mixins: [router_params],
    components: { china_address_select },

    data() {
        return {
            edit: false,
            loading: false,
            form: _.cloneDeep(defaultObj),
            formRules: {
                driverName: { required: true, message: '不能为空', trigger: 'change' },
                driverLicenseType: { required: true, message: '不能为空', trigger: 'change' },
                phone: { required: true, message: '不能为空', trigger: 'change' },
                ownerCity: { required: true, message: '不能为空', trigger: 'change' },
                idNo: { required: true, message: '不能为空', trigger: 'change' },
                idExpiredDate: { required: true, message: '不能为空', trigger: 'change' },
                supplierId: { required: true, message: '不能为空', trigger: 'change' },
                idHeadUrl: { required: true, message: '不能为空', trigger: 'change' },
                idBackUrl: { required: true, message: '不能为空', trigger: 'change' },
            },
        };
    },



    methods: {
        init_data_default(params) {
            this.edit = !!params.edit
            if (this.edit) {
                if (params.id) {
                    this.loading = true
                    this.$ajax({
                        url: "/tms-api/base/TmsDriverInfoRpc/selectById.json",
                        method: 'post',
                        data: { id: params.id },
                        success: (res) => {
                            this.loading = false
                            this.form = Object.assign({}, _.cloneDeep(defaultObj), res.data)
                            this.fixTabLabel()
                        }
                    })
                }
            }
            this.fixTabLabel()
        },
        fixTabLabel() {
            if (this.edit) {
                this.$emit("tagModifyLabel", { _key: 'label_name_code', name: "编辑司机", code: this.form.driverName || "" })

                // this.$emit('tagModifyLabel', {
                //     label: "编辑司机 [{code}]",
                //     option: { code: "" || this.form.driverName }
                // })
            } else {
                this.$emit('tagModifyLabel', "新增司机")
            }
        },

        submit() {
            this.$refs['form'].validate((valid, obj) => {

                if (valid) {
                    this.$ajax({
                        url: "/tms-api/base/TmsDriverInfoRpc/saveUpdate.json",
                        method: 'post', type: 'json',
                        data: this.form,
                        success: (res) => {
                            this.$message.success(this.$tt('tip_submit_success'))

                            this.return_emit(null, "reload")
                            this.return_page_back()

                        }
                    })
                } else {
                    this.$message.error(this.$tt('form_validate_error'))
                    return false;
                }
            });

        },
    }
};

</script>
<style></style>
